﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using L = Science.Mathematics.LinearAlgebra;

namespace Strang3Ed.Chapter02.Section6
{
    public class Example03
    {
        public Example03()
        {
        }
        private string result;
        public string Result
        {
            get { return result; }
        }
        public void Compute()
        {
            double[,] x = {{1.0,2.0},                           
                           {4.0,9.0}};
           
            L.Matrix A = new L.Matrix(x);

            L.FactorizationPAeqLU obj = new L.FactorizationPAeqLU(A);
            obj.Compute();

            L.Matrix Lo = obj.LowerTriangular;

            result += Lo.ToString();

            L.Matrix U = obj.UpperTriangular;

            result += U.ToString();

            double[] y = { 5.0, 21.0 };

            L.Vector b = new L.Vector(y);

            L.LinearEquation eq1 = new L.LinearEquation(Lo, b);
            eq1.Solve();

            L.Vector c = new L.Vector(eq1.Solution);
            L.LinearEquation eq2 = new L.LinearEquation(U, c);
            eq2.Solve();

            result += eq2.Solution[0].ToString()+"   "
                +eq2.Solution[1].ToString();
        }
    }
}
/*
1     0     
4     1     

1     2     
0     1     

3   1   
*/

